#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/7/22  9:29
# @Author: 余浪人
# @email: yulangren520@gmail.com

from apps.models import BaseModel, db
from apps.models.content_model import TL_Content_Model


class TL_Order_Model(BaseModel):
    sub_uuid = db.Column(db.String(16), db.ForeignKey(TL_Content_Model.uuid), comment='商品UUID')
    order_id = db.Column(db.String(16), unique=True, comment='订单ID')
    pro = db.relationship('TL_Content_Model', backref='order_model')

    def keys(self):
        return 'sub_uuid', 'order_id'


class TL_PayOrder_Model(BaseModel):
    buyer_logon_ID = db.Column(db.String(32), comment='买家登陆ID')
    buyer_user_ID = db.Column(db.String(32), comment='买家用户ID')
    send_pay_date = db.Column(db.DateTime, comment='购买时间')
    total_amount = db.Column(db.String(10), comment='订单金额')
    out_trade_no = db.Column(db.String(16), db.ForeignKey(TL_Order_Model.order_id), comment='订单编号')
    trade_no = db.Column(db.String(128), unique=True, comment='支付宝订单编号')
    message = db.Column(db.String(128), comment='订单支付状态')
    pro = db.relationship('TL_Order_Model', backref='payOrder_model')

    def __repr__(self):
        return f'订单编号:<{self.out_trade_no}>'

    def keys(self):
        return 'buyer_logon_ID', 'buyer_user_ID', 'send_pay_date', 'total_amount', 'out_trade_no', 'trade_no', 'message'
